package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpSROListPageUtil extends SeleniumPageUtil{
	
	public final static By SROL_SPAN_HEADER = By.id("ctl44_SROs_Header_lblHeader");
	public final static By SROL_IMG_EXPORT_PREFERENCES = By.id("ctl44_SROs_Header_imgPreferences");
	public final static By SROL_IMG_EXPORT = By.id("ctl44_SROs_Header_imgExcelExport");
	// when click an element of scope, should refresh the result page, refresh over the image hide
	public final static By SROL_IMG_REFRESH = By.id("ctl44_SROs_Header_imgRefresh");
	public final static By SROL_LINK_SCOPE = By.xpath("//*[@id='8a3f4cdb-9914-4d67-a302-802e96f65040']/a");
	
	// elements of scope show when click or focus on the scope link
	public final static By SROL_LI_MY_SROS = By.name("My SROs");
	public final static By SROL_LI_MY_FE_TEAM = By.name("My FE Team");
	public final static By SROL_LI_MY_WAREHOUSES = By.name("My Warehouses");
	public final static By SROL_LI_MY_WAREHOUSES_BY_CUSTOMER = By.name("My Warehouses By Customer");
	public final static By SROL_LI_ALL = By.name("All");
	public final static By SROL_LI_SITE_AUDITS_BY_STATUS_WHSE = By.name("Site Audits by Status/Whse");
	
	// the find/new link is under the li label
	public final static By SROL_LI_FIND = By.name("Find");
	public final static By SROL_LI_NEW = By.name("New");
	
	public final static By SROL_TD_PAGE = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr/td[1]");
	public final static By SROL_SPAN_PAGE_START_NO = By.id("ctl44_SROs_PagingTop_lblPagingPageNumber");
	public final static By SROL_TD_OF = By.xpath("//*[@id='form1']/table/tbody/tr[2]/td/div/table[2]/tbody/tr/td[3]");
	public final static By SROL_SPAN_PAGE_COUNT = By.id("ctl44_SROs_PagingTop_lblPagingPageCount");
	
	public final static By SROL_INPUT_FIRST = By.id("ctl44_SROs_PagingTop_imgFirst");
	public final static By SROL_INPUT_PREVIOUS = By.id("ctl44_SROs_PagingTop_imgPrevious");
	public final static By SROL_INPUT_NEXT = By.id("ctl44_SROs_PagingTop_imgNext");
	public final static By SROL_INPUT_LAST = By.id("ctl44_SROs_PagingTop_imgLast");
	
	public final static By SROL_IMG_FILTER_1 = By.id("ctl44_SROs_filter_1");
	public final static By SROL_IMG_FILTER_2 = By.id("ctl44_SROs_filter_2");
	public final static By SROL_IMG_FILTER_3 = By.id("ctl44_SROs_filter_3");
	public final static By SROL_IMG_FILTER_4 = By.id("ctl44_SROs_filter_4");
	public final static By SROL_IMG_FILTER_5 = By.id("ctl44_SROs_filter_5");
	public final static By SROL_IMG_FILTER_6 = By.id("ctl44_SROs_filter_6");
	public final static By SROL_IMG_FILTER_7 = By.id("ctl44_SROs_filter_7");
	public final static By SROL_IMG_FILTER_8 = By.id("ctl44_SROs_filter_8");
	public final static By SROL_IMG_FILTER_9 = By.id("ctl44_SROs_filter_9");
	public final static By SROL_IMG_FILTER_10 = By.id("ctl44_SROs_filter_10");
	public final static By SROL_IMG_FILTER_11 = By.id("ctl44_SROs_filter_11");
	public final static By SROL_IMG_FILTER_12 = By.id("ctl44_SROs_filter_12");
	public final static By SROL_IMG_FILTER_13 = By.id("ctl44_SROs_filter_13");
	
	// default scope
	public final static By SROL_TH_SRO_NO = By.id("ctl44_SROs_sort_1");
	public final static By SROL_TH_INCIDENT_NO = By.id("ctl44_SROs_sort_2");
	public final static By SROL_TH_TYPE = By.id("ctl44_SROs_sort_3");
	public final static By SROL_TH_STATUS = By.id("ctl44_SROs_sort_4");
	public final static By SROL_TH_DESCRIPTION = By.id("ctl44_SROs_sort_5");
	public final static By SROL_TH_CUSTOMER = By.id("ctl44_SROs_sort_6");
	public final static By SROL_TH_USER = By.id("ctl44_SROs_sort_7");
	public final static By SROL_TH_OPENED = By.id("ctl44_SROs_sort_8");
	public final static By SROL_TH_UPDATED = By.id("ctl44_SROs_sort_9");
	public final static By SROL_TH_CLOSED = By.id("ctl44_SROs_sort_10");
	
	// My FE Team of Scope Link
	public final static By SROL_TH_FE_SRO_ID = By.id("ctl44_SROs_sort_1");
	public final static By SROL_TH_FE_CUSTOMER = By.id("ctl44_SROs_sort_2");
	public final static By SROL_TH_FE_OPEN_DATE = By.id("ctl44_SROs_sort_3");
	public final static By SROL_TH_FE_STATUS = By.id("ctl44_SROs_sort_4");
	public final static By SROL_TH_FE_SRO_TYPE = By.id("ctl44_SROs_sort_5");
	public final static By SROL_TH_FE_DESCRIPTION = By.id("ctl44_SROs_sort_6");
	public final static By SROL_TH_FE_WAREHOUSE = By.id("ctl44_SROs_sort_7");
	public final static By SROL_TH_FE_ADDRESS = By.id("ctl44_SROs_sort_8");
	public final static By SROL_TH_FE_INCIDENT_ID = By.id("ctl44_SROs_sort_9");
	public final static By SROL_TH_FE_PRIORITY = By.id("ctl44_SROs_sort_10");
	public final static By SROL_TH_FE_SITE_AUDIT_CREATE = By.id("ctl44_SROs_sort_11");
	public final static By SROL_TH_FE_SITE_AUDIT_STATUS = By.id("ctl44_SROs_sort_12");
	public final static By SROL_TH_FE_CUST_TICKET_NO = By.id("ctl44_SROs_sort_12");
	
	// My Warehouses of Scope Link
	public final static By SROL_TH_MW_SRO_ID = By.id("ctl44_SROs_sort_1");
	public final static By SROL_TH_MW_CUSTOMER = By.id("ctl44_SROs_sort_2");
	public final static By SROL_TH_MW_OPEN_DATE = By.id("ctl44_SROs_sort_3");
	public final static By SROL_TH_MW_STATUS = By.id("ctl44_SROs_sort_4");
	public final static By SROL_TH_MW_ASSIGNED_TO = By.id("ctl44_SROs_sort_5");
	public final static By SROL_TH_MW_SRO_TYPE = By.id("ctl44_SROs_sort_6");
	public final static By SROL_TH_MW_DESCRIPTION = By.id("ctl44_SROs_sort_7");
	public final static By SROL_TH_MW_ADDRESS = By.id("ctl44_SROs_sort_8");
	public final static By SROL_TH_MW_INCIDENT_ID = By.id("ctl44_SROs_sort_9");
	public final static By SROL_TH_MW_PRIORITY = By.id("ctl44_SROs_sort_10");
	public final static By SROL_TH_MW_SITE_AUDIT_CREATE = By.id("ctl44_SROs_sort_11");
	public final static By SROL_TH_MW_SITE_AUDIT_STATUS = By.id("ctl44_SROs_sort_12");
	public final static By SROL_TH_MW_CUST_TICKET_NO = By.id("ctl44_SROs_sort_12");
	
	// My Warehouses by Customer of Scope Link
	public final static By SROL_TH_MWBC_SRO_ID = By.id("ctl44_SROs_sort_1");
	public final static By SROL_TH_MWBC_OPEN_DATE = By.id("ctl44_SROs_sort_2");
	public final static By SROL_TH_MWBC_STATUS = By.id("ctl44_SROs_sort_3");
	public final static By SROL_TH_MWBC_ASSIGNED_TO = By.id("ctl44_SROs_sort_4");
	public final static By SROL_TH_MWBC_SRO_TYPE = By.id("ctl44_SROs_sort_5");
	public final static By SROL_TH_MWBC_DESCRIPTION = By.id("ctl44_SROs_sort_6");
	public final static By SROL_TH_MWBC_WAREHOUSE = By.id("ctl44_SROs_sort_7");
	public final static By SROL_TH_MWBC_ADDRESS = By.id("ctl44_SROs_sort_8");
	public final static By SROL_TH_MWBC_INCIDENT_ID = By.id("ctl44_SROs_sort_9");
	public final static By SROL_TH_MWBC_PRIORITY = By.id("ctl44_SROs_sort_10");
	public final static By SROL_TH_MWBC_SITE_AUDIT_CREATE = By.id("ctl44_SROs_sort_11");
	public final static By SROL_TH_MWBC_SITE_AUDIT_STATUS = By.id("ctl44_SROs_sort_12");
	public final static By SROL_TH_MWBC_CUST_TICKET_NO = By.id("ctl44_SROs_sort_13");
	
	// All SROs of Scope Link
	public final static By SROL_TH_ALL_SRO_ID = By.id("ctl44_SROs_sort_1");
	public final static By SROL_TH_ALL_CUSTOMER = By.id("ctl44_SROs_sort_2");
	public final static By SROL_TH_ALL_OPEN_DATE = By.id("ctl44_SROs_sort_3");
	public final static By SROL_TH_ALL_STATUS = By.id("ctl44_SROs_sort_4");
	public final static By SROL_TH_ALL_ASSIGNED_TO = By.id("ctl44_SROs_sort_5");
	public final static By SROL_TH_ALL_SRO_TYPE = By.id("ctl44_SROs_sort_6");
	public final static By SROL_TH_ALL_DESCRIPTION = By.id("ctl44_SROs_sort_7");
	public final static By SROL_TH_ALL_WAREHOUSE = By.id("ctl44_SROs_sort_8");
	public final static By SROL_TH_ALL_ADDRESS = By.id("ctl44_SROs_sort_9");
	public final static By SROL_TH_ALL_INCIDENT_ID = By.id("ctl44_SROs_sort_10");
	public final static By SROL_TH_ALL_PRIORITY = By.id("ctl44_SROs_sort_11");
	public final static By SROL_TH_ALL_SITE_AUDIT_CREATE = By.id("ctl44_SROs_sort_12");
	public final static By SROL_TH_ALL_SITE_AUDIT_STATUS = By.id("ctl44_SROs_sort_13");
	public final static By SROL_TH_ALL_CUST_TICKET_NO = By.id("ctl44_SROs_sort_14");
	
	// Site Audits by Status/Whse of Scope Link
	public final static By SROL_TH_SA_WAREHOUSE= By.id("ctl44_SROs_sort_1");
	public final static By SROL_TH_SA_OPEN = By.id("ctl44_SROs_sort_2");
	public final static By SROL_TH_SA_ON_SITE = By.id("ctl44_SROs_sort_3");
	public final static By SROL_TH_SA_ON_SITE_COMPLETE = By.id("ctl44_SROs_sort_4");
	public final static By SROL_TH_SA_DATA_ENTRY = By.id("ctl44_SROs_sort_5");
	public final static By SROL_TH_SA_PENDSALES = By.id("ctl44_SROs_sort_7");
	public final static By SROL_TH_SA_COMPLETE = By.id("ctl44_SROs_sort_8");
	public final static By SROL_TH_SA_NOT_BEGUN = By.id("ctl44_SROs_sort_9");
	public final static By SROL_TH_SA_OPEN_SROS = By.id("ctl44_SROs_sort_10");
	
	// elements of Find Window
	public final static By SROL_SPAN_FIND_SRO_BY = By.id("ctl44_lblFind");
	public final static By SROL_SELECT_FIND_SRO_BY = By.id("ctl44_cboSearchType");
	public final static By SROL_INPUT_SEARCH = By.id("ctl44_txtSearch");
	public final static By SROL_INPUT_BUTTON_FIND = By.id("ctl44_btnFind");
	public final static By SROL_INPUT_CANCEL_FIND = By.id("ctl44_btnCancelFind");
	
	// elements of New Window
	// SROL_DIV_CREATE is whole window
	public final static By SROL_DIV_CREATE = By.id("ctl44_pnlCreate");
	public final static By SROL_SELECT_SRO_TYPE = By.id("ctl44_cboSroTypes");
	public final static By SROL_INPUT_CREATE = By.id("ctl44_btnCreate");
	public final static By SROL_INPUT_CANCEL = By.id("ctl44_btnCancelCreate");
		
	// elements under Site Audits by status/Whse 
	public final static By SROL_TD_WAREHOUSE = By.xpath("//*[@id='ctl44_SROs_ReportOutput']/table/tbody/tr/td[2]/a/../preceding-sibling::td[1]");
	public final static By SROL_LINK_OPEN_SROS = By.xpath("//*[@id='ctl44_SROs_ReportOutput']/table/tbody/tr/td[2]/a");
	public final static By SROL_SPAN_RESULT = By.id("ctl44_SiteAuditsListReport_ReportOutput");
	
	public static void enterSROListPage() {
		SpHomePageUtil.enter();
		SpHomePageUtil.enterSROListPage();
	}
	public static void waitForPageToLoad() {
		// list page in content area
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.selectFrame(SpHomePageUtil.HOME_FRAME_CONTENT_NAME);
		SeleniumUtil.waitOnElements(new By[]{
				SROL_IMG_EXPORT_PREFERENCES, SROL_IMG_EXPORT, SROL_LINK_SCOPE, SROL_LI_FIND, SROL_LI_NEW, SROL_INPUT_FIRST, SROL_INPUT_PREVIOUS, SROL_INPUT_NEXT, SROL_INPUT_LAST
			});
		
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_IMG_EXPORT_PREFERENCES));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_IMG_EXPORT));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_LINK_SCOPE));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_LI_FIND));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_LI_NEW));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_INPUT_FIRST));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_INPUT_PREVIOUS));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_INPUT_NEXT));
		SeleniumUtil.isDisplayed(SeleniumUtil.findElement(SROL_INPUT_LAST));
	}
	
	/**wait for refresh result*/
	public static void waitForResultRefresh(){
		long beforeWait = System.currentTimeMillis();
		long afterWait;
		boolean refreshEnd = !SeleniumUtil.findElements(SROL_IMG_REFRESH).get(0).getAttribute("style").contains("display: none");
		
		while(refreshEnd){
			afterWait = System.currentTimeMillis();
			if((afterWait - beforeWait) > 60 * 1000){
				SeleniumUtil.fail("timeout 60 seconds not response");
				return;
			}else{
				SeleniumUtil.waitForFixedMilliseconds(1000);
				SpSROListPageUtil.waitForPageToLoad();
				refreshEnd = !SeleniumUtil.findElements(SROL_IMG_REFRESH).get(0).getAttribute("style").contains("display: none");
			}
		}
	}
}
